package com.css.dzj.dzjdzqs.modules.datafromzfjg.service.impl;

import com.alibaba.fastjson.JSON;
import com.css.dzj.dzjdzqs.common.util.HttpClientUtil;
import com.css.dzj.dzjdzqs.modules.datafromzfjg.entity.JgLhjgJcdxEntity;
import com.css.dzj.dzjdzqs.modules.datafromzfjg.mapper.JgLhjgJcdxMapper;
import com.css.dzj.dzjdzqs.modules.datafromzfjg.service.JgLhjgJcdxService;
import com.css.dzj.dzjdzqs.modules.datafromzfjg.vo.JgLhjgJcdxVo;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class JgLhjgJcdxServiceImpl implements JgLhjgJcdxService {

    @Autowired
    private JgLhjgJcdxService jcdxService;
    @Value("${ZFJG_URL}")
    private String zfjgUrl;
    @Autowired
    private JPAQueryFactory jpaQueryFactory;
    @Autowired
    private JgLhjgJcdxMapper jgLhjgJcdxMapper;
    @Override
    public void addJcdxMsg()  {
        try {
            String list = HttpClientUtil.doGet(zfjgUrl + "/lhjg/jglhjgjcdx/queryAllJcdx");
            List<JgLhjgJcdxVo> results = JSON.parseArray(list, JgLhjgJcdxVo.class);
            for (JgLhjgJcdxVo result : results) {
                JgLhjgJcdxEntity jgLhjgJcdxEntity = new JgLhjgJcdxEntity();
                jgLhjgJcdxEntity.setId(result.getId());
                jgLhjgJcdxEntity.setTaskno(result.getTaskno());
                jgLhjgJcdxEntity.setObjectName(result.getObjectname());
                jgLhjgJcdxEntity.setEnterpriseCreditcode(result.getEnterprisecreditcode());
                jgLhjgJcdxEntity.setSuperviseObjectType(result.getObjectType());
                /*//本地查询数据库是否有该数据
                 JgLhjgJcdxEntity old = jcdxService.getById(result.getId());
                 if(old == null){
                     //数据库不存在该数据 添加新数据


                 }else{
                     //数据库已存在该数据 更新数据

                 }*/
                jgLhjgJcdxMapper.save(jgLhjgJcdxEntity);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
